<template>
	<view class="webView-page">
		<view id="view">123</view>
		<web-view id="webView" :src="url" @message="webViewMsg" @onPostMessage="webViewMsg"></web-view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: '',
				params: {}
			}
		},

		mounted() {
			const query = uni.createSelectorQuery().in(this);
			query.select('#webView').fields({
				id: true,
				dataset: true,
				context: true
			}, data => {
				console.log("得到布局位置信息" + JSON.stringify(data));
				console.log("节点离页面顶部的距离为" + data.top);
			})
		},
		onLoad(params) {
			// uni.getLocation({
			// 	type: 'gcj02',
			// 	geocode: true,
			// 	isHighAccuracy: true,
			// 	highAccuracyExpireTime: 4000,
			// 	success: location => {
			// 		console.log(location);
			// 		let {
			// 			longitude,
			// 			latitude
			// 		} = location
			// 		console.log(longitude + ',' + latitude);
			// 		this.$u.api.GaodeApi.coordinateConvert({
			// 			key: '9670df2781265a076d02bd0aaf33dc1a',
			// 			locations: longitude + ',' + latitude, // 经度在前，纬度在后
			// 		}).then(res => {
			// 			if (res.status == 1) {
			// 				console.log(res);
			// 				const locations = res.locations.split(',')
			// 				this.url =
			// 					`https://m.amap.com/picker/?keywords=写字楼,小区,学校&zoom=15&center=${locations[0]},${locations[1]}&radius=1000&total=20&key=ab23c3d3e86a5a8a34122cecbd942d26`
			// 				this.currentLocations = res.locations
			// 				this.$u.api.GaodeApi.inverseGeocode({
			// 					key: '9670df2781265a076d02bd0aaf33dc1a',
			// 					location: res.locations,
			// 				}).then(geocode => {
			// 					console.log('geocode:', geocode);
			// 				})
			// 			}
			// 		})
			// 	},
			// 	fail: res => {
			// 		console.log(res);
			// 	},
			// 	complete(e) {
			// 		console.log(e);
			// 	}
			// })
			this.url = `/hybrid/html/blueTooth/blueTooth.html`
			// this.url = `/pages/common/msgWebview1`

			this.params = params
		},
		methods: {
			test() {
				console.log('1');
			},
			webViewMsg(e) {
				console.log(e);
				let data = e.detail.data[0].action

				this.$u.vuex('vuex_location', data)

				uni.setStorage({
					key: 'vuex_location',
					data: data,
				})
				uni.$emit('selectMap',data)
				uni.switchTab({
					url: '/pages/sys/workbench/archives/add'
				});
				// console.log(this.params.noticeId);
				// this.$u.api.record.info(4, this.params.noticeId).then(res => {
				// 	let urlArr = res.data.url && res.data.url != '' ? res.data.url.split(',') : []
				// 	urlArr.push(data.url)
				// 	return this.$u.api.record.edit(4, {
				// 		noticeId: this.params.noticeId,
				// 		archivesId: this.vuex_archives.archivesId,
				// 		jsonStr: [{}]
				// 	})
				// }).then(res => {
				// 	console.log(res);
				// 	if (res.code == 200) {
				// 		this.$refs.uToast.show({
				// 			isTab: true,
				// 			title: '上传成功',
				// 			type: 'success',
				// 			url: '/pages/sys/detail/index',
				// 			duration: 1000
				// 		})
				// 	}
				// })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.webView-page {
		// background-color: #f3f4f6;
		height: 100vh;
	}
</style>
